package com.cars.grpc.server.account.service;

import com.alibaba.fastjson2.JSON;
import com.cars.grpc.hello.HelloReply;
import com.cars.grpc.hello.HelloRequest;
import com.cars.grpc.hello.MyServiceGrpc;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * @author caoqianfan
 * @date 2024/2/6 9:45
 */
@GrpcService
@Slf4j
public class HelloService extends MyServiceGrpc.MyServiceImplBase {

    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
        log.debug("receive msg: " + JSON.toJSONString(request));
        HelloReply reply = HelloReply.newBuilder()
                .setMessage("Hello ==> " + request.getName())
                .build();
        log.debug("response msg: " + JSON.toJSONString(reply));
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }

}